package com.zbkj.crmeb.store.controller;


import com.common.CommonPage;
import com.crmeb.core.common.CommonResult;
import com.common.PageParamRequest;
import com.zbkj.crmeb.store.model.ProductInformation;
import com.zbkj.crmeb.store.request.ProductInformationRequest;
import com.zbkj.crmeb.store.service.IProductInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 商品信息表 前端控制器
 * </p>
 *
 * @author xx
 * @since 2022-05-12
 */
@RestController
@RequestMapping("api/admin/store/information")
@Api(tags = "商品信息")
public class ProductInformationController {
    @Autowired
    private IProductInformationService productInformationService;

    @ApiOperation(value = "商品信息新增或编辑")
    @RequestMapping(value = "/saveOrUpdInformation", method = RequestMethod.POST)
    public CommonResult<Object> saveOrUpdInformation(@RequestBody ProductInformation productInformation, HttpServletRequest servletRequest){
        return productInformationService.saveOrUpdInformation(productInformation) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "商品信息分页查询")
    @RequestMapping(value = "/getInformationPage", method = RequestMethod.POST)
    public CommonResult<CommonPage<ProductInformation>> getInformationPage(ProductInformationRequest request, PageParamRequest pageParamRequest, HttpServletRequest servletRequest){
        return CommonResult.success(productInformationService.getInformationPage(request,pageParamRequest));
    }

    @ApiOperation(value = "商品信息列表查询")
    @RequestMapping(value = "/getInformationList", method = RequestMethod.POST)
    public CommonResult<List<ProductInformation>> getInformationList(HttpServletRequest servletRequest){
        return CommonResult.success(productInformationService.getInformationList());
    }

    @ApiOperation(value = "商品信息删除")
    @RequestMapping(value = "/delInformation", method = RequestMethod.GET)
    public CommonResult<Object> delInformation(@RequestParam Integer id, HttpServletRequest servletRequest){
        return productInformationService.delInformation(id) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "商品信息批量删除")
    @RequestMapping(value = "/delInformationByIds", method = RequestMethod.POST)
    public CommonResult<Object> delInformationByIds(@RequestBody List<Integer> ids, HttpServletRequest servletRequest){
        return productInformationService.removeByIds(ids) ? CommonResult.success() : CommonResult.failed();
    }

}

